﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;

namespace App.Views.VehicleService
{
    public partial class PrintUseVehicleList : System.Web.Mvc.ViewPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Views/VehicleQueryService/rptUseVehicle.rdlc");
                ReportDataSource datasource = new ReportDataSource();
                datasource.Name = "dsUseVehicle";
                string driverNO = Request.QueryString["DriverNO"].Trim();
                string vehicleNO = Request.QueryString["VehicleNO"].Trim();
                string starttime = Request.QueryString["StartTime"];
                string endtime = Request.QueryString["EndTime"];
                DateTime st = DateTime.MinValue;
                DateTime et = DateTime.MaxValue;
                try
                {
                    st = DateTime.Parse(starttime);
                }
                catch
                {
                    st = DateTime.MinValue;
                }
                try
                {
                    et = DateTime.Parse(endtime);
                    et = et.AddDays(1);
                }
                catch
                {
                    et = DateTime.MaxValue;
                }
                datasource.Value = App.Models.ReportClass.GetUseVehicleRecord(st,et,driverNO,vehicleNO);
                bool groupbydriver = true;
                if (!string.IsNullOrWhiteSpace(vehicleNO))
                {
                    groupbydriver = false;
                }
                ReportParameter[] parameters = new ReportParameter[3];
                parameters[0] = new ReportParameter("groupbydriver", groupbydriver.ToString());
                parameters[1] = new ReportParameter("starttime", starttime);
                parameters[2] = new ReportParameter("endtime", endtime);  
                ReportViewer1.LocalReport.SetParameters(parameters);

                ReportViewer1.LocalReport.DataSources.Add(datasource);
            } 
        }
    }
}